<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ChurnTable>" %>
<%@ Import Namespace="TfsReports.Web.Models"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"><%= ViewData["Title"] %></asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" src="Scripts/timeplot/timeplot-api.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="Scripts/timeplot/jquery.timeplot.js"></script>
    
    <script type="text/javascript" src="Scripts/jquery-ui-1.7.2.custom.min.js"></script>
    <link type="text/css" rel="stylesheet" href="Content/smoothness/jquery-ui-1.7.2.custom.css" />
    
    <script type="text/javascript">
        $(function(){
            $('#start').datepicker({ showOn: 'button', buttonImage: 'Content/calendar.png', buttonImageOnly: true, dateFormat: 'yy-mm-dd', maxDate: '+0d', defaultDate: -21, changeMonth: true, changeYear: true, showButtonPanel: true, onClose: function(dateText, inst) { $('form').submit(); } }).css('width', '5em');
            $('#stop').datepicker({ showOn: 'button', buttonImage: 'Content/calendar.png', buttonImageOnly: true, dateFormat: 'yy-mm-dd', maxDate: '+0d', defaultDate: +0, changeMonth: true, changeYear: true, showButtonPanel: true, onClose: function(dateText, inst) { $('form').submit(); } }).css('width', '5em');
            $('table.chartable').TimePlot('timeplot-container');
        });
        $(window).resize(function() { $.ResizeChartsForWindow(); });
    </script>
    <style type="text/css">
        #timeplot-container { margin-bottom: 10px; }
        /*div, th, td { font: x-small sans-serif; }*/
        /*table.chartable td, table.chartable th { padding: 0 6px 0 6px; }*/
        table.chartable td { text-align: right; }
        /*table.chartable tr.odd { background-color: #eeeeee; }*/
        .border-red { border-bottom: 1px solid red; }
        .border-green { border-bottom: 1px solid green; }
        .border-blue { border-bottom: 1px solid blue; }
        .border-yellow { border-bottom: 1px solid yellow; }
        .border-cyan { border-bottom: 1px solid cyan; }
        .border-purple { border-bottom: 1px solid purple; }
        .border-orange { border-bottom: 1px solid orange; }
        .border-lime { border-bottom: 1px solid lime; }
        .strong { font-weight: bold; }
        div.column { width: 49%; float: left; }
        div.clear { clear: both; }
        .right { text-align: right; }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div class="column">
        <h2><%= ViewData["Title"] %></h2>
    </div>
    <div class="column right">
    <% using (Html.BeginForm("Plot", "Churn", new { start = Request["start"], stop = Request["stop"] }, FormMethod.Get, new { @class = "right" })) { %>

        <label for="start">Start:</label><%= Html.TextBox("start")%>
        
        <label for="stop">Stop:</label><%= Html.TextBox("stop")%>
        
        <%= Html.DropDownList("Qualifier") %>
        
        <input type="submit" value="Go" /><br />
        <%=Html.ActionLink("Clear Cache", "Flush", "Home", new{redirectAction="Plot", redirectController="Churn"}, null) %>
    <% } %>
    </div>
    <div class="clear"></div>
    <div id="timeplot-container"></div>
    <table class="chartable">
        <thead>
            <tr>
                <td></td>
                <% foreach (Person person in Model.People) { %><th><%= Html.ActionLink(person.Title, "Index", new { start = Model.Start.ToString("yyyy-MM-dd"), stop = Model.End.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd"), personId = person.Id })%></th><% } %>
            </tr>
        </thead>
        <tbody>
        <% foreach (KeyValuePair<DateTime, Dictionary<int, Changes>> dateData in Model) { %>
            <tr>
                <th><%= Html.ActionLink(dateData.Key.ToString("yyyy-MM-dd"), "Index", new{start=dateData.Key, stop=dateData.Key.AddDays(1).AddSeconds(-1)})%></th>
                <% foreach (KeyValuePair<int, Changes> peopleData in dateData.Value) { %><td><% switch (Request["Qualifier"]) { %>
                <% case "Churn": %><%= Html.Encode(peopleData.Value.Churn)%><% break; %>
                <% case "LinesAdded": %><%= Html.Encode(peopleData.Value.LinesAdded) %><% break; %>
                <% case "LinesModified": %><%= Html.Encode(peopleData.Value.LinesModified) %><% break; %>
                <% case "LinesDeleted": %><%= Html.Encode(peopleData.Value.LinesDeleted) %><% break; %>
                <% default: %><%= Html.Encode(peopleData.Value.Commits) %><% break; %>
                <% } %></td><% } %>
            </tr>
        <% } %>
        </tbody>
        <thead>
            <tr>
                <th>Totals:</th>
                <% foreach (Person person in Model.People) { %><td class="strong"><% switch (Request["Qualifier"]) { %>
                <% case "Churn": %><%= Html.Encode(Model.Totals[person.Id].Churn)%><% break; %>
                <% case "LinesAdded": %><%= Html.Encode(Model.Totals[person.Id].LinesAdded)%><% break; %>
                <% case "LinesModified": %><%= Html.Encode(Model.Totals[person.Id].LinesModified)%><% break; %>
                <% case "LinesDeleted": %><%= Html.Encode(Model.Totals[person.Id].LinesDeleted)%><% break; %>
                <% default: %><%= Html.Encode(Model.Totals[person.Id].Commits)%><% break;  } %></td><% } %>
            </tr>
        </thead>
    </table>

</asp:Content>
